package com.hxy.tlias.controller;

import com.hxy.tlias.pojo.AliOSSProperties;
import com.hxy.tlias.pojo.Result;
import com.hxy.tlias.utils.AliyunOSSUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.beans.factory.annotation.Value;

@Slf4j
@RestController
public class UploadController {
    @Autowired
    private AliOSSProperties aliOSSProperties;

    /**
     * 文件上传，阿里云OSS存储
     * @return
     */
    @PostMapping("/upload")
    public Result upload(String name,Integer age, MultipartFile file) throws Exception{
       
        String originalFilename = file.getOriginalFilename();
        log.info("原始文件名：{}",originalFilename);
        String extName = originalFilename.substring(originalFilename.lastIndexOf("."));
        String url = AliyunOSSUtils.upload(aliOSSProperties.getEndpoint(), aliOSSProperties.getBucket(), file.getBytes(), extName);
        return Result.success(url);
    }


}

